package com.ruoyi.blindBoxManage.controller;

import com.ruoyi.blindBoxManage.domain.Class;
import com.ruoyi.blindBoxManage.service.IClassService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/class/class")
public class ClassController extends BaseController
{
    @Autowired
    private IClassService classService;

    /**
     * 查询分类列表
     */
    @PreAuthorize("@ss.hasPermi('class:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(Class classs)
    {
        startPage();
        List<Class> list = classService.selectClassList(classs);
        return getDataTable(list);
    }

    /**
     * 导出分类列表
     */
    @PreAuthorize("@ss.hasPermi('class:class:export')")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Class classs)
    {
        List<Class> list = classService.selectClassList(classs);
        ExcelUtil<Class> util = new ExcelUtil<Class>(Class.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('class:class:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(classService.selectClassById(id));
    }

    /**
     * 新增分类
     */
    @PreAuthorize("@ss.hasPermi('class:class:add')")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Class classs)
    {
        return toAjax(classService.insertClass(classs));
    }

    /**
     * 修改分类
     */
    @PreAuthorize("@ss.hasPermi('class:class:edit')")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Class classs)
    {
        return toAjax(classService.updateClass(classs));
    }

    /**
     * 删除分类
     */
    @PreAuthorize("@ss.hasPermi('class:class:remove')")
    @Log(title = "分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(classService.deleteClassByIds(ids));
    }
}
